Coding Art by Yu Zhang & Mathias Funk
Author:Yu Zhang & Mathias Funk
Language: eng
Format: epub
ISBN: 9781484262641
Publisher: Apress
? Think about this
Try extending this example by checking the SHIFT key to make the rectangle move faster in one direction when pressing SHIFT. What else could you influence with the keyboard?
Precise control is a strength of the keyboard; every key press counts. As we will see in the next example, we can also work with the content of the keys that are pressed. Letâs start by simply printing the pressed key as a bold character on the canvas.
This example uses a brief setup and an empty draw function, and most of the action happens in the keyPressed function . In the beginning, we load a font that we previously created with Processing tools. How did we do that? Open Processing and the Tools menu. There is an option âCreate font...â that allows to pick a font from your computer, determine the size, and convert it into a format that Processing can use directly. It works better if you specify the right font size already, so the rendered text is sharp in the end. Processing creates a new font file that should be located in the same folder as the Processing sketch.
Print the pressed key as a bold character on the canvas
PFont f;
void setup() {
size(400, 400);
// load a specific font to print text
f = loadFont("InterUI-ExtraBold-250.vlw");
background(0);
}
void draw() {}
void keyPressed() {
// draw character
background(0); fill(255);
// set text rendering options
textFont(f, 250);
textSize(250);
// measure character width
float charWidth = textWidth(key);
// draw character centered
text(key, (width - charWidth) / 2., 300);
}
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1832)
API Testing and Development with Postman by Dave Westerveld(1703)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(1574)
Machine Learning for Algorithmic Trading by Stefan Jansen(1499)
Software Architecture for Busy Developers by Stéphane Eyskens(1494)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1463)
Delphi GUI Programming with FireMonkey by Andrea Magni(1333)
Cloud Native with Kubernetes by Alexander Raul(1296)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1279)
Automate It with Zapier by Kelly Goss(1247)
Software Architecture Patterns for Serverless Systems by John Gilbert(1242)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1221)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1218)
Practical Node-RED Programming by Taiji Hagino(1204)
Mastering React Test-Driven Development by Daniel Irvine(1193)
Delphi Programming Projects by William Duarte(1185)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1151)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1150)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1148)